module ApplicationHelper
	def short_ymd date
		date.strftime("%Y-%m-%d") if date
	end

  def long_ymd date
    date.strftime("%Y年%m月%d日%H时%M分") if date
  end
  #确认是否审核通过
  def check_shenhe new_id
    news = NewsGroup.where(news_id:new_id)
    flag = false
 
    if news.blank?
    else
      news.each do |new|
        if  new.group_id==15 && !new.check.blank?
          flag= true
        end
      end
    end
    flag
  end
  #确认是否审核过,并且蓓退稿
  def check_shenhe_back new_id
    news = NewsGroup.where(news_id:new_id)
    flag = false
 
    if news.blank?
    else
      news.each do |new|
        if  new.group_id==15 && new.check==2
          flag= true
        end
      end
    end
    flag
  end

  #确认是否审核通过
  def check_shenhe_pass new_id
    news = NewsGroup.where(news_id:new_id)
    flag = false
 
    if news.blank?
    else
      news.each do |new|
        if  new.group_id==15 && new.check==1
          flag= true
        end
      end
    end
    flag
  end

  #审核状态
  def check_shenhe_role new_id
    news = NewsGroup.where(news_id:new_id)
    group = GroupUser.find_by_user_id current_user.id
    flag = false
    
    if news.blank?
    else
      news.each do |new|
        if group.group_id == new.group_id
          return new.check
        end
      end
    end
  end


  def active_nav_new(page)
    _action = case page.to_i
    when 1
      :xyyw
    when 3
      :zhxw 
    when 4
      :job
    when 5
      :join_exchange
    when 6
      :distance
    when 7
      :picture_hl
    when 8
      :voide_hl
    end
    active_nav_tag _action if _action
  end

  def breadcrumb place
    {"important_news" => " > 校园要闻", "synthesis_new" => " > 综合新闻", "job" => " > 招生就业", "join_exchange" => " > 合作交流", "important_messages" => " > 校园快讯", "distance" => " > 深度报道", "picture_hl" => " > 图说华理", "voide_hl" => " > 媒体华理"}["#{place}"] 
  end

  def active_nav_tag(name)
    content_for :active_nav do 
      name.to_s
    end
  end

  #查询按钮
  def select_button
    submit_tag "  查  询  " ,:class => "btn btn-info btn-sm"
  end

  #新增按钮
  def new_button options={}
    link_to options[:name] || " 新建稿件 ",options[:url].to_s,:class => "btn btn-primary btn-sm"
  end

  #必填标签
  def must_label
    content_tag(:span,'*', style: "color:red;font-size:18px;margin-left:5px;")
  end


  def guolv_title content
    p (raw(content))
    content=(raw(content)).gsub("&nbsp;"," ").gsub("&#8226;","•")
    content.length>20 ? "#{content[0..19] }...":content
  end
  
    def guolv_title2 content
    content=(raw(content)).gsub("&nbsp;"," ").gsub("&#8226;","•")
    content.length>27 ? "#{content[0..26] }...":content
  end


 def guolv_title3 content
    content=(raw(content)).gsub("&nbsp;"," ").gsub("&#8226;","•")
    content.length>50 ? "#{content[0..49] }...":content
  end
  
  
   def guolv_title_all content
    p 11111111111111111111222222222222233333333333
    content=(raw(content)).gsub("&nbsp;"," ").gsub("&#8226;","•")
    content
  end

  def guolv_time (pubtime ,created_at)
    content = pubtime;
    if pubtime.nil? 
      content = created_at;
    end
    content
  end
  
  def save_dangan(start_time ,end_time)
    
  end
end
